package web.i18n;

import java.util.Locale;

import org.apache.wicket.Component;
import org.apache.wicket.Session;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.model.ResourceModel;

public class InternacionalizacionHome extends WebPage{
	private static final long serialVersionUID = 1L;

	public InternacionalizacionHome() {
		Form<Void> form = new Form<Void>("form");
		setOutputMarkupId(true);
		this.add(form.add(
			new Label("locale", new PropertyModel<Locale>(Session.get(), "locale")),
			new Label("label", new ResourceModel("labels.label")),
			new Label("idioma", new ResourceModel("labels.idioma")),
			boton()
		));
	}

	private Component boton() {
		return new AjaxSubmitLink("cambiarLocal") {
			private static final long serialVersionUID = 1L;

			@Override
			protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
				Session.get().setLocale(Locale.ENGLISH);
				target.add(InternacionalizacionHome.this);
			}
			
			@Override
			protected void onError(AjaxRequestTarget target, Form<?> form) {
				
			}
		};
	}
}